package com.finance.framework.lang;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.BigDecimalConverter;
import org.apache.commons.beanutils.converters.DateConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * Created by CBWL on 2017/4/12.
 */
public class BeanUtils extends org.apache.commons.beanutils.BeanUtils {
    static{
        DateConverter converter = new DateConverter(null);
        converter.setPattern("yyyy-mm-dd HH:mm:ss");
        ConvertUtils.register(converter, Date.class);
        BigDecimalConverter bigDecimalConverter=new BigDecimalConverter(null);
        ConvertUtils.register(bigDecimalConverter, BigDecimal.class);
        IntegerConverter integerConverter=new IntegerConverter(null);
        ConvertUtils.register(integerConverter, Integer.class);

    }
    public static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException {
        org.apache.commons.beanutils.BeanUtils.copyProperties(dest, orig);
    }
    public static void populate(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException {
        org.apache.commons.beanutils.BeanUtilsBean.getInstance().populate(bean, properties);
    }

}
